import { getToken } from "../utlis/cookie"

export default function ({ route, next, store }) {

    let token = getToken() // 获取token值

    let whiteList = ["/login", "/reg"]

    if (token) {

        let hasRoles = store.getters.roles && store.getters.roles.length > 0

        if (hasRoles) {
            // console.log(1);
            // store.dispatch("users/getUserInfo", token)


        } else {
         console.log(2);
            store.dispatch("users/getUserInfo", token)

        }


    } else {
        if (whiteList.includes(route.path)) {  // 如果跳转页面在白名单


        } else {
            next({ path: "/login", redirect: true })
        }


    }


}